package com.lagou.service.impl;

import com.lagou.base.StatusCode;
import com.lagou.dao.CourseContentDao;
import com.lagou.dao.impl.CourseContentDaoImpl;
import com.lagou.pojo.Course;
import com.lagou.pojo.Course_Lesson;
import com.lagou.pojo.Course_Section;
import com.lagou.service.CourseContentService;
import com.lagou.utils.DateUtils;

import java.util.List;

public class CourseContentServiceImpl implements CourseContentService {
    CourseContentDao contentDao=new CourseContentDaoImpl();
    @Override
    public List<Course_Section> findSectionAndLessonByCourseId(int courseId) {
        List<Course_Section> sections= contentDao.findSectionAndLessonByCourseId(courseId);
        return sections;
    }

    @Override
    public Course findCourseByCourseId(int courseId) {
        Course course = contentDao.findCourseByCourseId(courseId);
        return course;
    }

    @Override
    public String saveSection(Course_Section section) {
        section.setStatus(2);
        String date = DateUtils.getDateFormart();
        section.setCreate_time(date);
        section.setUpdate_time(date);
        int row = contentDao.saveSection(section);
        if(row>0){
            String result = StatusCode.SUCCESS.toString();
            return result;
        }else{
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }

    @Override
    public String updateSection(Course_Section section) {
        String date = DateUtils.getDateFormart();
        section.setUpdate_time(date);
        int row = contentDao.updateSection(section);
        if(row>0){
            String result = StatusCode.SUCCESS.toString();
            return result;
        }else{
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }

    @Override
    public String updateSectionStatus(int id, int status) {
        int row=contentDao.updateSectionStatus(id,status);
        if(row>0){
            String result = StatusCode.SUCCESS.toString();
           return result;
        }else{
            String result=StatusCode.FAIL.toString();
            return result;
        }
    }

    @Override
    public String saveLesson(Course_Lesson lesson) {
        String date = DateUtils.getDateFormart();
        lesson.setCreate_time(date);
        lesson.setUpdate_time(date);
        int row = contentDao.saveLesson(lesson);
        if(row>0){
            String result = StatusCode.SUCCESS.toString();
            return result;
        }else{
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }

    @Override
    public String updateLesson(Course_Lesson lesson) {
        String date=DateUtils.getDateFormart();
        lesson.setUpdate_time(date);
        int row = contentDao.updateLesson(lesson);
        if(row>0){
            String result = StatusCode.SUCCESS.toString();
            return result;
        }else{
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }


}
